package com.bkm.factory;

public enum TypeEnum {

    Ocean("海洋", 1, 4),

    Sky("天空", 5, 8),

    Land("陸地", 9, 12),

    ;

    private final String typeName;

    private final int monthStartRange;

    private final int monthEndRange;

    TypeEnum(String typeName, int monthStartRange, int monthEndRange) {
        this.typeName = typeName;
        this.monthStartRange = monthStartRange;
        this.monthEndRange = monthEndRange;
    }

    public String getTypeName() {
        return typeName;
    }

    /**
     * 判斷生日在不在區間
     *
     * @param birth
     * @return
     */
    private boolean inRange(String birth) {
        if (birth.length() < 2) {
            return false;
        }
        String monthStr = birth.substring(0, 2);
        try {
            Integer month = Integer.parseInt(monthStr);
            return this.monthStartRange <= month && month <= this.monthEndRange;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 判斷寶可夢屬於哪個類型
     *
     * @param birth
     * @return
     */
    public static TypeEnum typeOf(String birth) {
        TypeEnum[] values = TypeEnum.values();
        for (TypeEnum value : values) {
            if (value.inRange(birth)) {
                return value;
            }
        }
        return null;
    }
}


